package org.example.controller;

import org.example.pojo.Result;
import org.example.utils.AilOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件上传到本地磁盘
        String originalFilename = file.getOriginalFilename();
        //保证文件名唯一，防止文件覆盖
        String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
//        file.transferTo(new File("C:\\Users\\LENOVO\\Desktop\\aaa\\" + filename));
        //添加阿里云oss存储
        String url = AilOssUtil.uploadFile(filename,file.getInputStream());
        return Result.success(url);
    }
}
